Skip to content

Encoding Equilibrium (DNM)#4058

Draft
balacij wants to merge 6 commits intomainfrom
equilibrium
Draft

Encoding Equilibrium (DNM)#4058
balacij wants to merge 6 commits intomainfrom
equilibrium

Conversation

@balacij
Copy link
Collaborator

@balacij balacij commented May 9, 2025

Do Not Merge (DNM).

We can use this to discuss encoding equilibrium in Drasil and spin issues off this PR if necessary.

I will annotate the PR first.

I've only encoded equilibrium in the context of a simple supply/demand curve thus far.

Copy link
Collaborator Author

@balacij balacij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bulk of the comments.

Comment on lines -66 to +75
, TMs [] []
, TMs [] (Label : stdFields)
, GDs [] [] HideDerivation
, DDs [] [] HideDerivation
, IMs [] [] HideDerivation
, DDs [] (Label : stdFields) HideDerivation
, IMs [] ([Label, Input, Output, InConstraints, OutConstraints] ++ stdFields) HideDerivation
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input, Output, (In/Out)Constraints are rows that are only permitted for IMs. I'm not quite sure why. Are "inputs" not the input variables of a hypothetical function being defined?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because 'definitions' don't have input/output, and many theories are relational, so again input/output makes no sense for them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure I'm following. What is the difference between a data definition (which defines QDefinitions) and an EquationalModel-based (i.e., QDefinition-defining) instance model?

Is "input/output" in regard to the "system's" inputs, outputs, and intermediate variables? If so, I think that should still be relevant to data definitions, which can be used to interpret input variables to intermediate variables (e.g., for unit conversion, etc.), no?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do remember that "F = ma" is usually used to get 'a' as output, given F and m as input!

I think we ought to use different vocabulary for input and output of a system, and equations where some variables can be substituted for.

It is true that the intent of a data definition is that the new symbol is defined by the computation where we imagine substituting for the (implicitly occuring) variables in the RHS. A data-definition is implicitly a function.

Comment on lines -96 to +104
_quants = [] :: [QuantityDict],
_instModels = [] :: [InstanceModel],
_datadefs = [] :: [DataDefinition],
_quants = quantities, -- Odd: The Table of Symbols is mostly filled without this list!!!! Also, even though the table of symbols is being filled in, there is text "There are no symbols." placed above the table!
_instModels = instanceModels, -- Surprisingly, putting this here is not what triggers it to get rendered.
_datadefs = dataDefinitions, -- ^
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something that needs to be spun off into 2 new tickets.

  1. The SRS is rendered using the instance models and data definitions taken from the ChunkDB rather than here. We should probably change that.
  2. The Table of Symbols is partially rendered without filling in the _quants field, but completely filled in when passing this list to it. This should be investigated a little bit more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deeper questions are:

  1. where should the information come from? We used to do things "by hand" because there was no other choice. But, of course, Drasil should automate things as much as possible. So it is a good thing that some information comes from the theories rather than hand-built!
  2. what is the difference between the "background information" necessary, and the meta-data needed to build a particular system? And should that information be gathered? Divided up?

Comment on lines +183 to +184
equilibrium :: IdeaDict
equilibrium = nc "equilibrium" $ nounPhrase "equilibrium" "equilibria"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once defined, never used! Should we be using it? If so, how?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never used because you're not "doing it right". For example, it should have been used on line 295, and indeed on line 202 as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, none of the constructors for QuantityDicts let us give them a plain IdeaDict. All of the constructors are keen on extracting an IdeaDict from something else or creating one that is immediately associated with the Q-D-.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. On line 295, you could have gotten the nounPhrase by using the lens defined for that. What do you think the code should instead look like?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have expected to be able to pass in the entire IdeaDict (seeing as QuantityDicts currently nest an IdeaDict), and for the QuantityDict to only carry a UID reference to said IdeaDict.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have the power to change Drasil: do it! Introduce new functions that let you do that. That's the fun part, of seeing things that should be better, and just improving them.

Comment on lines +193 to +200
equilibriumQ :: QuantityDict
equilibriumQ = mkQuant' -- A somewhat odd variant of `mkQuant` that re-orders argument and adds staging to the `Symbol`
"inEquilibrium"
(nounPhrase "in equilibrium" "all equilibria") -- duplicates the IdeaDict
Nothing -- UnitDefn
Boolean
(autoStage $ label "inEquilibrium")
Nothing -- "abbreviation String"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QuantityDict's mkQuant' and related smart constructors are interesting because they create their own IdeaDicts that they associate with themselves. QDefinition's mkQuantDef and related smart constructors are similar, except they also create a DefinedQuantityDict, which also creates a ConceptChunk. In the future, it might be that our smart constructors are stateful too (in reference to #2873 (comment)).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed a sign that we're trying to be too clever. We need to rethink this.

priceQ = mkQuant'
"priceQuant" -- duplicates the IdeaDict
(cn "price")
Nothing -- UnitDefn // FIXME: Uh oh! There's seemingly no way we can define a new unit: $CAD.s
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting that I wouldn't be able to create numbers of the form $ X CAD, but that I would be able to create CAD units at least. I don't see a clear way to doing that without it being 'derived' from the SI unit system.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that currencies are 'units', per se. They are a classification system, and we ought to support more of them than just SI.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I hadn't realized that UnitDefn and our unit system in general was only meant for physical quantities following the SI.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - it's a side-effect of Drasil being focused on scientific software, so that was the most important classification system. Types were second. Now we might need more classification systems to be added (and most likely, our code refactored to reflect this fact.)

Comment on lines +324 to +327
-- ^ I'm deliberately choosing to use applePrice here because I want to use this
-- in an instance model, which (I believe) should mean that there are only
-- 'concrete' variables (i.e., problem-related variables, not the abstract ones
-- imported from the hypothetical library that would contain equilibrium)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can/should we differentiate between abstract and concrete variables?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should. Don't know if we currently can.

(cn "equilibrium apple price")
Nothing -- UnitDefn
Real -- Space
(autoStage $ sub lP $ label "A,Eq") -- Hack because of lack of support for symbol "corners" in Drasil.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lack of adequate support*. Related to #1606.

Comment on lines +359 to +366
equilibriumPriceLinearSDQIM :: InstanceModel
equilibriumPriceLinearSDQIM = imNoDerivNoRefs
(equationalModel' equilibriumApplePriceLinearSDQD)
[] -- Inputs -- What are they? Why is this only here and not in the TM?
equilibriumApplePriceLinearSDQ -- Output -- not everything will have an output!
[UpFrom (Exc, int 0)] -- Output constraints: price > 0 -- why can't I put gtZerConstr
"equilibriumApplePriceIM"
[] -- Notes ([Sentence])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The important bit is really the QDefinition, which contains a DefinedQuantityDict (DQD) and a defining formula for the DQD. Now:

  1. What are the "inputs"? If the DQD is a function (i.e., a function-typed variable), is it the inputs to the function? In Projectile's IM:calOfLandingDist, $p_\text{land}$ is noted as having two inputs: $v_\text{launch}$ and $\theta$, but $p_\text{land}$ is not a function. If it should be (and I don't think it should be), then why is $g$ not a part of its inputs?
  2. Why isn't the list of input and output variables and their corresponding constraints in the QDefinition. Same with the notes. Why wouldn't they be part of the QDefinition?
  3. While we're here, why not the derivation and the references?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think input and output are / ought to be theory-level concepts and not chunk-level.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that input and output should be at the theory level.

For the specific example of $p_\text{land}$, $g$ is not an input because it is a constant. Having $g$ as a constant is a modelling choice (assumption). If we were at a different elevation, or on a different planet, $g$ would be different. Drasil shouldn't force us to have one model for any part of physics (or any other science). With different assumptions, we get different models. In the projectile SRS we have gravAccelValue (The acceleration due to gravity is assumed to have the value provided in the section for Values of Auxiliary Constants). If this assumption is removed, we would have $g$ as an input (runtime variability for $g$). We could also have a different binding time for $g$ if we supported program families. We could set the binding time for $g$ as the specification time. We almost have this now, but it would have to be changed manually, instead of the specification being explicitly parameterized by its variabilities.

Comment on lines +119 to +123
{-
DefinedQuantityDict seems like a wart. It seems like it's only necessary when
we want to assert that a quantity has an English interpretation along with a
mathematical one (i.e., a variable).
-}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like D-Q-D really just wants to be smart constructor as I mentioned earlier. There's no reason why a QuantityDict couldn't also have a description.

-- | Renders definition tables (Data, General, Theory, etc.).
makeDefn :: L.DType -> [(String,[LayoutObj])] -> Doc -> Doc
makeDefn _ [] _ = error "L.Empty definition"
makeDefn _ [] _ = error "Definition table has no designated rows to render!"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably something that should just be ported over to main.

Comment on lines -66 to +75
, TMs [] []
, TMs [] (Label : stdFields)
, GDs [] [] HideDerivation
, DDs [] [] HideDerivation
, IMs [] [] HideDerivation
, DDs [] (Label : stdFields) HideDerivation
, IMs [] ([Label, Input, Output, InConstraints, OutConstraints] ++ stdFields) HideDerivation
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because 'definitions' don't have input/output, and many theories are relational, so again input/output makes no sense for them.

Comment on lines -96 to +104
_quants = [] :: [QuantityDict],
_instModels = [] :: [InstanceModel],
_datadefs = [] :: [DataDefinition],
_quants = quantities, -- Odd: The Table of Symbols is mostly filled without this list!!!! Also, even though the table of symbols is being filled in, there is text "There are no symbols." placed above the table!
_instModels = instanceModels, -- Surprisingly, putting this here is not what triggers it to get rendered.
_datadefs = dataDefinitions, -- ^
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deeper questions are:

  1. where should the information come from? We used to do things "by hand" because there was no other choice. But, of course, Drasil should automate things as much as possible. So it is a good thing that some information comes from the theories rather than hand-built!
  2. what is the difference between the "background information" necessary, and the meta-data needed to build a particular system? And should that information be gathered? Divided up?

Comment on lines +183 to +184
equilibrium :: IdeaDict
equilibrium = nc "equilibrium" $ nounPhrase "equilibrium" "equilibria"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never used because you're not "doing it right". For example, it should have been used on line 295, and indeed on line 202 as well.

Comment on lines +193 to +200
equilibriumQ :: QuantityDict
equilibriumQ = mkQuant' -- A somewhat odd variant of `mkQuant` that re-orders argument and adds staging to the `Symbol`
"inEquilibrium"
(nounPhrase "in equilibrium" "all equilibria") -- duplicates the IdeaDict
Nothing -- UnitDefn
Boolean
(autoStage $ label "inEquilibrium")
Nothing -- "abbreviation String"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed a sign that we're trying to be too clever. We need to rethink this.


priceQ :: QuantityDict
priceQ = mkQuant'
"priceQuant" -- duplicates the IdeaDict
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is technically a duplication -- but it shouldn't be, because the 'concept' of a price, and a variable that holds a 'price' value are completely different. And the bug is that you shouldn't do (cn "price") below but refer to price ^. term instead.

Nothing -- UnitDefn
(mkFunction [Real] Integer)
(autoStage $ sub cS lL)
Nothing -- Abbreviation
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SCS has tons of abbreviations. Maybe it's just that finance has less so for fundamental quantities?

linearDemandQ :: QuantityDict
linearDemandQ = mkQuant'
"linearDemandQuant"
(pn "price-dependant apple demand")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here all the pns below: I think you're abusing pn here, a different constructor should be used.

Also, these 'noun phrases' should be built compositionally! The word 'apple' should never be repeated or even mentioned in all of thse (in the source). Similarly, demand, marginal, supply and price should all be abstracted.

Comment on lines +324 to +327
-- ^ I'm deliberately choosing to use applePrice here because I want to use this
-- in an instance model, which (I believe) should mean that there are only
-- 'concrete' variables (i.e., problem-related variables, not the abstract ones
-- imported from the hypothetical library that would contain equilibrium)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should. Don't know if we currently can.

linearSupplyDD = ddENoRefs
linearSupplyQD
Nothing -- Derivation
"linearSupplyDD" -- "ShortName"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought short names were for human consumption!?

Comment on lines +359 to +366
equilibriumPriceLinearSDQIM :: InstanceModel
equilibriumPriceLinearSDQIM = imNoDerivNoRefs
(equationalModel' equilibriumApplePriceLinearSDQD)
[] -- Inputs -- What are they? Why is this only here and not in the TM?
equilibriumApplePriceLinearSDQ -- Output -- not everything will have an output!
[UpFrom (Exc, int 0)] -- Output constraints: price > 0 -- why can't I put gtZerConstr
"equilibriumApplePriceIM"
[] -- Notes ([Sentence])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think input and output are / ought to be theory-level concepts and not chunk-level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants